package chapter7classloader;

public class P79 {

    //双亲委派机制，查看一个类，是否是由此类加载器的父类加载器实现，如果已经实现了，返回已经加载了的类的实例。避免类的混乱 具体可看loadClass方法的源码
    public static class MyClassLoader extends ClassLoader{

        //如果自己实现类加载的话就破坏了双亲委派模式
        @Override
        public Class<?> loadClass(String name) throws ClassNotFoundException {
            return super.loadClass(name);
        }

        /**
         * Finds the class with the specified <a href="#name">binary name</a>.
         * This method should be overridden by class loader implementations that
         * follow the delegation model for loading classes, and will be invoked by
         * the {@link #loadClass <tt>loadClass</tt>} method after checking the
         * parent class loader for the requested class.  The default implementation
         * throws a <tt>ClassNotFoundException</tt>.
         *
         * @param name The <a href="#name">binary name</a> of the class
         * @return The resulting <tt>Class</tt> object
         * @throws ClassNotFoundException If the class could not be found
         * @since 1.2
         */
        //如果需要实现双亲委派机制 那么就可以继承这个类
        @Override
        protected Class<?> findClass(String name) throws ClassNotFoundException {
            return super.findClass(name);
        }
    }
}
